package com.example.test.operate.resource;

import com.example.test.operate.POJO.PO.OperateRolePO;
import com.example.test.operate.service.IOperateRoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * <desc>
 *
 * </desc>
 *
 * @createDate 2021-07-16
 */
@RestController
public class OperateRoleServiceResource {

    @Autowired
    IOperateRoleService iOperateRoleService;
/**
 * <desc>
 *         获取角色列表
 * </desc>
 *
 * @param
 * @return
 * @author liuyu
 * @createDate
 */
    @RequestMapping(path = "/operate/role/list")
    public List<OperateRolePO> getRoleList( OperateRolePO operateRolePO){

        return iOperateRoleService.getRoleList(operateRolePO);
    }
    /**
     * <desc>
     *      获取分页数据
     * </desc>
     *
     * @param
     * @return
     * @author liuyu
     * @createDate
     */

    @RequestMapping(path = "/operate/role/page2")
    public PageInfo<OperateRolePO> getPageList(@RequestParam ("currentPage") Integer currentPage,
                                               @RequestParam ("pageSize") Integer pageSize,
                                                OperateRolePO OperateRolePO){

        PageHelper.startPage(currentPage,pageSize);
        System.out.println(OperateRolePO);
        List<OperateRolePO> operateRolePOS = iOperateRoleService.getRoleList(OperateRolePO);
                PageInfo<OperateRolePO>  pageInfo = new PageInfo<>(operateRolePOS );
                return pageInfo;

    }

    /**
     * <desc>
     *        添加角色
     * </desc>
     *
     * @param
     * @return
     * @author liuyu
     * @createDate
     */
    @RequestMapping(path = "/operate/role/addrole")
    public Integer addRole(OperateRolePO operateRolePO){
        return iOperateRoleService.save(operateRolePO);
    }



    /**
     * <desc>
     *         修改角色
     * </desc>
     *
     * @param
     * @return
     * @author liuyu
     * @createDate
     */
    @RequestMapping(path = "/operate/role/updaterole")
    public Integer updateRole(OperateRolePO operateRolePO){
        return iOperateRoleService.update(operateRolePO);
    }

    /**
     * <desc>
     *            分配人员
     * </desc>
     *
     * @param
     * @return
     * @author liuyu
     * @createDate
     */
    @RequestMapping(path = "/operate/role/commit")
    public Integer getCommitContent(@RequestParam("userId") String userId,
                                         @RequestParam ("roleId") String roleId
    ){
        System.out.println("userId-----------------"+userId);
        if(userId == ""){
          return new Integer(1);
      }else {
          return iOperateRoleService.saveRoleUsers(roleId, userId);

      }

    }

    /**
     * <desc>
     *      保存角色菜单资源
     * </desc>
     *
     * @param
     * @return
     * @author liuyu
     * @createDate 2021-07-23
     */
    @RequestMapping(path = "/operate/role/saverolefunction")
    public Integer saveRoleFunction(@RequestParam("roleId") String roleId,@RequestParam("functionIds") List<String>functionIds){
        System.out.println(functionIds);
        return iOperateRoleService.saveRoleFunction(roleId,functionIds);
    }

}
